﻿namespace UtilZ.Dotnet.Ex.Communication.Net.Web
{
    /// <summary>
    /// 一段url
    /// </summary>
    public class UrlSegment
    {
        /// <summary>
        /// Api参数信息
        /// </summary>
        public ApiParameterInfo ApiParameterInfo { get; private set; }

        /// <summary>
        /// url中的参数名
        /// </summary>
        public string UrlParaName { get; private set; }

        /// <summary>
        /// 固定url
        /// </summary>
        public string FixUrl { get; private set; }

        /// <summary>
        /// url模板参数前缀
        /// </summary>
        public string ParaPrefix { get; private set; }

        /// <summary>
        /// url模板参数后缀
        /// </summary>
        public string ParaSuffix { get; private set; }



        /// <summary>
        /// 构造函数-构造FromQueryString和FromBody
        /// </summary>
        /// <param name="urlParaName"></param>
        /// <param name="apiParameterInfo"></param>
        public UrlSegment(string urlParaName, ApiParameterInfo apiParameterInfo)
        {
            this.UrlParaName = urlParaName;
            this.ApiParameterInfo = apiParameterInfo;
        }

        /// <summary>
        /// 构造函数-构造FromUrl
        /// </summary>
        /// <param name="urlParaName"></param>
        /// <param name="paraPrefix"></param>
        /// <param name="paraSuffix"></param>
        /// <param name="apiParameterInfo"></param>
        public UrlSegment(string urlParaName, string paraPrefix, string paraSuffix, ApiParameterInfo apiParameterInfo)
            : this(urlParaName, apiParameterInfo)
        {
            this.ParaPrefix = paraPrefix;
            this.ParaSuffix = paraSuffix;
        }

        /// <summary>
        /// 构造函数-构造None
        /// </summary>
        /// <param name="fixUrl">固定url段</param>
        public UrlSegment(string fixUrl)
        {
            this.FixUrl = fixUrl;
        }



        /// <summary>
        /// 重写ToString
        /// </summary>
        /// <returns>String</returns>
        public override string ToString()
        {
            var parameterInfo = this.ApiParameterInfo;
            return $"{parameterInfo.TemplateParameterType.ToString()}   {parameterInfo.ParameterInfo.Position}  {UrlParaName}   {parameterInfo.ParameterInfo.ParameterType.FullName}";
        }
    }
}
